$(function () {
//焦点图轮播
let pic = document.getElementById('pic');
let index = 1;
let timer;
//自动播放
function fun() {
    clearInterval(timer);
    timer = setInterval(function () {
        index++;
        if (index == 4) {
            index = 1
        }
        $('li').removeClass('active');
        $('li:nth-child(' + (index) + ')').addClass('active');
        pic.src = 'images/ban' + index + '.jpg';
    }, 1000);

};
 fun();
 //鼠标放入，停止轮播
 $('.top_slide_wrap').mouseenter(function(){
    clearInterval(timer);
});
//鼠标离开，重启定时器
$('.top_slide_wrap').mouseleave(function(){
    fun();
});

 //新闻滚动
 let box = document.getElementById("express");
 let con1 = document.getElementById("con1");
 let con2 = document.getElementById("con2");
 let speed = 30;
 con2.innerHTML = con1.innerHTML;
 function scrollUp() {
     box.scrollTop++;
     if (box.scrollTop >= con1.scrollHeight) {
         box.scrollTop = 0;
     }        
 }
 setInterval(scrollUp, speed);


    //左边购物列表
    $(".fj ").hover(
        function () {
            $(this).siblings(".zj").show();
        },
        function () {
            $(this).siblings(".zj").hide();
        });

    //客户服务下拉条
    $("#serve").hover(
        function () {
            $('.ss_list_bg ').slideDown("slow");
        },
        function () {
            $('.ss_list_bg  ').slideUp("slow");
        });


    //鼠标悬停显示购物车
    $(".i_car  ").hover(
        function () {
            $('.last').show();
        },
        function () {
            $('.last').hide();
        });
    //点击加号改变input值 改变小计的值 改变总价的值
    $(".J_btnAddCount").each(function () {
        $(this).click(function () {
            //获取input值
            let count = parseFloat($(this).parents(".plush").find(".J_inputCount").val());
            //点击之后+1
            count++;
            $(this).parent(".plush").find(".J_inputCount").val(count);
             //获取商品单价
            let price = parseFloat($(this).parents(".clear").find('.cang').html());
           
             //计算商品小计
            let money = (price * count);
            $(this).parents(".clear").find(".J_smallTotalPrice").html(money);

         total();
                
        })  
    
    });
    
  //点击减号改变input值 改变小计的值 改变总价的值
    $(".J_btnDelCount").each(function () {
        $(this).click(function () {
              //获取input值
            let count = parseFloat($(this).parents(".plush").find(".J_inputCount").val());
             //点击之后减1
            count--;
            if (count <= 0) {
                return;
            }
            $(this).parent(".plush").find(".J_inputCount").val(count);
            //获取单价
            let price = parseFloat($(this).parents(".clear").find('.cang').html());
           
             //计算商品小计
            let money = (price * count);
            $(this).parents(".clear").find(".J_smallTotalPrice").html(money);
            total();
        })  
               
    });
    //商品删除
      $(".shop .clear a ").click(function(){
          $(this).parents('li').remove(); 
          total();
      })
      //计算商品总价  
      function total() {
          //计算每件商品价格
       let money1 = $(".shop .clear #money1").text();
       let money2 = $(".shop .clear #money2").text(); 
       let money3 = $(".shop .clear #money3").text(); 
       //获取商品总价添加到总价
       let totalMoney = Number(money1) + Number(money2) + Number(money3);
       $(".J_totalPrice").html(totalMoney);
      }
   
     
      

})
